<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class Admin extends Model
{
	public function login($data){
		$captcha = new \think\captcha\Captcha();
        if (!$captcha->check($data['code'])) {
            return 4;//验证码错误
        }
		$user = Db::name('admin')->where('username','=',$data['username'])->find();
		if ($user) {
			if ($user['password'] == md5($data['password'])){
				session('username', $user['username']);//用的助手函数创建session
				session('uid',$user['id']);
				return 3;//密码正确
			}else{
				return 2;//密码错误
			}
		}else{
			return 1;//用户不存在
		}
	}

}